package com.pattern.create.prototype;

import java.util.Hashtable;

public class PrototypeManager {

    private static PrototypeManager pm = new PrototypeManager();
    private Hashtable<String, Prototype> ht = new Hashtable<>();

    private PrototypeManager() {
        ht.put("a", new ConcretePrototypeA());
        ht.put("b", new ConcretePrototypeB());
    }

    public static PrototypeManager getPrototypeManager() {
        return pm;
    }

    public void addPrototype(String key, Prototype prototype) {
        ht.put(key, prototype);
    }

    public <T extends Prototype> T getPrototype(String key) {
        return (T) (ht.get(key).clone());
    }
}
